package com.zhuiyi.yiqingbackend.controller;

import com.zhuiyi.yiqingbackend.common.BaseResponse;
import com.zhuiyi.yiqingbackend.common.ResultUtils;
import com.zhuiyi.yiqingbackend.domain.Dead;
import com.zhuiyi.yiqingbackend.domain.request.AddDeadRequest;
import com.zhuiyi.yiqingbackend.domain.request.OnlyBaseId;
import com.zhuiyi.yiqingbackend.service.DeadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/dead")
@Api(value = "接口", tags = "死亡人员管理接口")
@CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
public class DeadController {
    @Resource
    private DeadService deadService;
    /**
     * 获取死亡人员列表
     */
    @GetMapping("/getDeads")
    @ApiOperation(value = "获取死亡人员列表", notes = "获取死亡人员列表")
    public BaseResponse<List<Dead>> getDeads(){
        List<Dead> deads = deadService.getDeads();
        return ResultUtils.success(deads);
    }

    /**
     * 根据id获取死亡人员
     */
    @GetMapping("/getDeadById/{id}")
    @ApiOperation(value = "根据id获取死亡人员", notes = "根据id获取死亡人员")
    public BaseResponse<Dead> getDeadById(@PathVariable int id){
        Dead dead = deadService.getDeadById(id);
        return ResultUtils.success(dead);
    }

    /**
     * 添加死亡人员
     */
    @PostMapping("/addDead")
    @ApiOperation(value = "添加死亡人员", notes = "添加死亡人员")
    public BaseResponse<Boolean> addDead(@RequestBody AddDeadRequest request){
        boolean result = deadService.addDead(request);
        return ResultUtils.success(result);
    }

    /**
     * 添加死亡人员 plus
     */
    @PostMapping("/addDead2")
    @ApiOperation(value = "添加死亡人员 plus ", notes = "添加死亡人员 plus ")
    public BaseResponse<Boolean> addDead2(@RequestBody OnlyBaseId onlyBaseId){//虽然只有1个参数，但用RequestBody 接受就得用以请求体来接受
        int id = onlyBaseId.getId();
        boolean ok = deadService.addDead2(id);
        return ResultUtils.success(ok);
    }

    /**
     * 删除死亡人员
     */
    @GetMapping("/deleteDead/{id}")
    @ApiOperation(value = "删除死亡人员", notes = "删除死亡人员")
    public BaseResponse<Boolean> deleteDead(@PathVariable int id){
        boolean result = deadService.deleteDead(id);
        return ResultUtils.success(result);
    }
}
